// pages/mine/winningRecordList/winningRecordList.js
import Common from '../../../common/common.js';
let common = new Common;
const app = getApp();
Page({
  data: {
    pageList:[],
    pageNumber: 1,
    isEnd: false, //是否到底
    type:0,//判断状态箭头朝下
    pstype:0,//判断配送方式箭头朝下
    setPsTypeNum:'',//设置状态值
    rotate:1,//设置查看收货地址的值
    // setPsMethodsNum:'',//设置配送方式值
    setPsTypeName:'全部',//设置状态值
    // setPsMethodsName:'配送方式',//设置配送方式值
    flg:0
  },
  // 展开状态可选择状态
  setType:function(e){
    this.setData({
      pstype:0
    })
    let type = e.currentTarget.dataset.type;
    if(type==0){
      this.setData({
        type:1
      })
    }else{
      this.setData({
        type:0
      })
    }
  },
  // 展开配送方式可选择配送方式
  pstype:function(e){
    this.setData({
      type:0
    })
    let pstype  = e.currentTarget.dataset.pstype;
    if(pstype==0){
      this.setData({
        pstype:1
      })
    }else{
      this.setData({
        pstype:0
      })
    }
  },
  // 选择配送状态
  setPsType:function(e){
    let type = e.currentTarget.dataset.type;//配送状态
    let typeName = e.currentTarget.dataset.typename;//配送状态
    console.log(e)
    this.setData({
      setPsTypeNum:type,
      setPsTypeName:typeName,
      type:0
    })
    this.getPageList(1,1)
  },
   // 选择配送方式
   setPsMethods:function(e){
    let type = e.currentTarget.dataset.type;//配送状态
    let typeName = e.currentTarget.dataset.typename;//配送状态
    this.setData({
      // setPsMethodsNum:type,
      // setPsMethodsName:typeName,
      pstype:0
    }) 
    this.getPageList(1,1)
   },
  //  点击其他地方隐藏选择框
  hide_slesct_bg:function(e){
    this.setData({
      type:0,
      pstype:0
    })
  },
  lookClickPs:function(e){
    
    console.log(e)
    let that = this;
    let uuid = e.currentTarget.dataset.uuid;
    that.setData({
      rotate:uuid
    })
    console.log(this.data.uuid)
    wx.showModal({
      title: "提示",
      content: "请确认是否配送？",
      showCancel: true,
      cancelText: "取消",
      confirmText: "确定",
      success: function (res) {
        console.log(res)
        if (res.confirm) {
         
          // return;
          // that.sureSubmit(uuid)
        }else{
          wx.showToast({
            title: '点击了取消',
            icon:'none'
          })
        }
      }
    })
    
  },
  // 复制订单号
  copy:function(e){
    var that = this;
    let orderNum = e.currentTarget.dataset.copy;
    wx.setClipboardData({
     //准备复制的数据
      data: orderNum,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
          icon:'none'
        });
      }
    });

  },
  // 确认配送
  sureSubmit:function(uuid){
    // return
    let data = {
      condition:{
        uuid:uuid
      }
    }
    common.requestAjax('/api/promotion-service/v1/memberWine/storeDelivery','GET').then(res=>{
      if (res.data.code) {
        wx.showToast({
          title: '配送成功',
          icon:'none'
        })
        setTimeout(() => {
          this.getPageList(1,1);
        }, 2000);
      }

    })
  },
  onLoad: function (options) {
    this.getPageList(1,1);
  },  
  onShow: function () {

  },
  getPageList(page, type){
    let setPsTypeNum;
    if(this.data.setPsTypeNum==9){
      setPsTypeNum = null
    }else if(this.data.setPsTypeNum==0){
      setPsTypeNum == 1
    }else if(this.data.setPsTypeNum==1){
      setPsTypeNum == 4
    }
    let data = {
      "size": 10,
      "current": page,
      "ascs": [],
      "descs": [],
      "condition": {
        // "orgSeq": app.globalData.orgSeq,
        "orgSeq": '4564564',
        'exchangeStatus':setPsTypeNum
        // "memberId": '',
        // "keyword": "",
        // "memberLevel": "",
        // "beginDate": '',
        // "endDate": '',
        // // 'deliveryType':this.data.setPsMethodsNum,//配送方式
        // 'isDeliver':this.data.setPsTypeNum,//配送状态
      }
    }
    common.requestAjax('/api/promotion-service/v1/memberWine/storeExchange','POST',data).then(res=>{
      if (res.data.code) {
        let arraylist = this.data.pageList || [];
        let isEnd = this.data.isEnd;
        if (type == 1) {
          //下拉刷新
          arraylist = res.data.records;
          isEnd = false;
        } else if (type == 2) {
          //上拉加载
          arraylist = arraylist.concat(res.data.records);
          if (res.data.records.length == 0) {
            //最后一行没数据 到底了
            isEnd = true;
          }
          setTimeout(() => {
            wx.hideLoading()
          }, 500)
        }
        this.setData({
          pageList: arraylist,
          isEnd,
        })
      }

    })
  },
  onReachBottom: function () {
    if (!this.data.isEnd) {
      let pageNumber = this.data.pageNumber;
      pageNumber += 1;

      this.getPageList(pageNumber, 2)

      wx.showLoading({
        title: '正在加载中...',
      })
      this.setData({
        pageNumber
      })
    }
  },
  lookClick(e){
    console.log(e)
   let rotate=e.currentTarget.dataset.index;
  if(this.data.flg==0){
    if(e.currentTarget.dataset.index==rotate){
      this.setData({
        rotate:0,
        flg:1
      })
    }
    
  }else{
    this.setData({
      rotate:1,
      flg:0
    })
  }
    // if(e.currentTarget.dataset.index==rotate){
    //   this.setData({
    //     rotate:0,
    //     flg1
    //   })
    // }else{
    //   this.setData({
    //     rotate:1
    //   })
    // }
    console.log(this.data.rotate)
   
  }
})